.TH std::forward_list::front 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::forward_list::front \- std::forward_list::front

.SH Synopsis
   reference front();             \fB(1)\fP \fI(since C++11)\fP
   const_reference front() const; \fB(2)\fP \fI(since C++11)\fP

   Returns a reference to the first element in the container.

   Calling front on an empty container causes undefined behavior.

.SH Parameters

   \fI(none)\fP

.SH Return value

   Reference to the first element.

.SH Complexity

   Constant.

.SH Notes

   For a container c, the expression c.front() is equivalent to *c.begin().

.SH Example

   The following code uses front to display the first element of a
   std::forward_list<char>:


// Run this code

 #include <forward_list>
 #include <iostream>

 int main()
 {
     std::forward_list<char> letters{'a', 'b', 'c', 'd', 'e', 'f'};

     if (!letters.empty())
         std::cout << "The first character is '" << letters.front() << "'.\\n";
 }

.SH Output:

 The first character is 'a'.

.SH See also

   push_front inserts an element to the beginning
              \fI(public member function)\fP
   pop_front  removes the first element
              \fI(public member function)\fP
